package com.kurumi.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.kurumi.mapper.BaseInfoMapper;
import com.kurumi.service.PageIndexRefService;
import com.kurumi.util.ObjectUtils;
@Service
public class PageIndexRefServiceImpl implements PageIndexRefService {

	@Autowired
	private BaseInfoMapper baseInfoMapper;
	
	@Override
	public Map<String, Map<String, Object>> getGbtDectRefs() {
		// TODO Auto-generated method stub
		Map<String,Map<String,Object>> pageIndexDectRefs = new HashMap<String,Map<String,Object>>();
		List<Map<String,Object>> allRefDatas = baseInfoMapper.getAllGbtDectPageIndexRefs();
		if(!allRefDatas.isEmpty()){
			for (Map<String, Object> refData : allRefDatas) {
				String code = ObjectUtils.getStringValue(refData.get("code"));
				String name = ObjectUtils.getStringValue(refData.get("name"));
				String numberCode = ObjectUtils.getStringValue(refData.get("number_code"));
				String charCode2 = ObjectUtils.getStringValue(refData.get("char_code2"));
				String charCode3 = ObjectUtils.getStringValue(refData.get("char_code3"));
				String tableCode = ObjectUtils.getStringValue(refData.get("table_code"));
				Map<String,Object> pageIndexDectRef = (Map<String,Object>)pageIndexDectRefs.get(tableCode);
				if(pageIndexDectRef==null){
					pageIndexDectRef = new HashMap<String,Object>(); 
					pageIndexDectRefs.put(tableCode, pageIndexDectRef);
				}
				Map<String, String> value = new HashMap<String, String>();
				value.put("code", code);
				value.put("name", name);
				value.put("numberCode", numberCode);
				value.put("charCode2", charCode2);
				value.put("charCode3", charCode3);
				if(!pageIndexDectRef.containsKey(code)){
					pageIndexDectRef.put(code, value);
				}
				if(!pageIndexDectRef.containsKey(name)){
					pageIndexDectRef.put(name, value);
				}
				if(numberCode!= null && !pageIndexDectRef.containsKey(numberCode)){
					pageIndexDectRef.put(numberCode, value);
				}
				if(charCode2!= null && !pageIndexDectRef.containsKey(charCode2)){
					pageIndexDectRef.put(charCode2, value);
				}
				if(charCode3!= null && !pageIndexDectRef.containsKey(charCode3)){
					pageIndexDectRef.put(charCode3, value);
				}
			}
		}
		return pageIndexDectRefs;
	}

	@Override
	public Map<String, Map<String, String>> getPageIndexWjtDectRefs() {
		// TODO Auto-generated method stub
		Map<String,Map<String,String>> pageIndexDectRefs = new HashMap<String,Map<String,String>>();
		List<Map<String,Object>> allRefDatas = baseInfoMapper.getAllWjtDectPageIndexRefs();
		if(!allRefDatas.isEmpty()){
			for (Map<String, Object> refData : allRefDatas) {
				String code = ObjectUtils.getStringValue(refData.get("code"));
				String name = ObjectUtils.getStringValue(refData.get("name"));
				String tableCode = ObjectUtils.getStringValue(refData.get("table_code"));
				Map<String,String> pageIndexDectRef = (Map<String,String>)pageIndexDectRefs.get(tableCode);
				if(pageIndexDectRef==null){
					pageIndexDectRef = new HashMap<String,String>(); 
					pageIndexDectRefs.put(tableCode, pageIndexDectRef);
				}
				if(!pageIndexDectRef.containsKey(code)){
					pageIndexDectRef.put(code, name);
				}
			}
		}
		return pageIndexDectRefs;
	}

}
